﻿
//文章分类
@helper PostType()
    {
    var db = new ShenLanCMS.Models.EntityContext();
    var pt = db.PostTypes;
    foreach (var item in pt)
    {
        <li><a href="/post/bytype/@item.PostTypeID">@item.TypeName</a> </li>
    }
}

//最新文章
@helper NewPosts()
    {
        var db = new ShenLanCMS.Models.EntityContext();
        var posts = db.Posts.Where(n => n.Status == 1).OrderByDescending(n => n.PubTime).Take(15);
        foreach (var item in posts)
        {
          <li>[<a href="/post/bytype/@item.PostTypeID">@item.GetPostType().TypeName</a>] <a href="/post/view/@item.PostID" title="@item.Title" target="_blank">@item.Title</a> [@item.PubTime.ToString()] (点击:@item.Click)</li>
        }
}
//最热文章
@helper HotPosts()
    {
        var db = new ShenLanCMS.Models.EntityContext();
        var posts = db.Posts.Where(n => n.Status == 1).OrderByDescending(n => n.Click).Take(15);
        foreach (var item in posts)
        {
         <li>[<a href="/post/bytype/@item.PostTypeID">@item.GetPostType().TypeName</a>] <a href="/post/view/@item.PostID" title="@item.Title" target="_blank">@item.Title</a> [@item.PubTime.ToString()] (点击:@item.Click)</li>
        }
}
//评论最多的文章
@helper MostCommentPosts()
    {
        var db = new ShenLanCMS.Models.EntityContext();
        var comments = db.Comments.OrderByDescending(n => n.PostID);
        List<ShenLanCMS.Models.Post> list = new List<ShenLanCMS.Models.Post>();
        foreach (var item in comments)
        {
            var p = db.Posts.Find(item.PostID);
            if (p != null && p.Status == 1)
            {
                list.Add(p);
            }
        }
        list = list.Distinct().Take(15).ToList();
        foreach (var item in list)
        {        
        <li>[<a href="/post/bytype/@item.PostTypeID">@item.GetPostType().TypeName</a>] <a href="/post/view/@item.PostID" title="@item.Title" target="_blank">@item.Title</a> [@item.PubTime.ToString()] (点击:@item.Click)</li>
        }
}
//顶最多文章
@helper DigGoodPosts()
    {
        var db = new ShenLanCMS.Models.EntityContext();
        var posts = db.Posts.Where(n => n.Status == 1).OrderByDescending(n => n.DigGood).Take(15);
        foreach (var item in posts)
        {
   <li>[<a href="/post/bytype/@item.PostTypeID">@item.GetPostType().TypeName</a>] <a href="/post/view/@item.PostID" title="@item.Title" target="_blank">@item.Title</a> [@item.PubTime.ToString()] (点击:@item.Click)</li>
        }
}
//踩最多文章
@helper DigBadPosts()
    {
        var db = new ShenLanCMS.Models.EntityContext();
        var posts = db.Posts.Where(n => n.Status == 1).OrderByDescending(n => n.DigBad).Take(15);
        foreach (var item in posts)
        {
  <li>[<a href="/post/bytype/@item.PostTypeID">@item.GetPostType().TypeName</a>] <a href="/post/view/@item.PostID" title="@item.Title" target="_blank">@item.Title</a> [@item.PubTime.ToString()] (点击:@item.Click)</li>
        }
}

//友情链接
@helper AllLinks()
    {
        var db = new ShenLanCMS.Models.EntityContext();
        var links = db.Links.Where(n => n.Status == 1).OrderBy(n => n.Sort);
        foreach (var item in links)
        {
            if (string.IsNullOrEmpty(item.Logo))
            {
               <li><a href="@item.SiteUrl" title="@item.SiteName" target="_blank">@item.SiteName</a></li>
            }
            else
            {
                <li><a href="@item.SiteUrl" title="@item.SiteName" target="_blank"><img src="@item.Logo" width="88px" height="31px" /></a></li>
            }
        }
}

//随机广告
@helper RandomAds()
    {
        var db = new ShenLanCMS.Models.EntityContext();
        var ads = from n in db.Ads select n;
        var ran = new Random().Next(ads.Count()); 
        var ad = ads.ToList();
        var html = "暂无广告";
        if(ads.Count()>0)
        {
           html= ad[ran].Content;
        }
       <div>
         @html
        </div> 
    }
        